{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "id": "3943489e",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "### http://n.cztv.com/ich/index-1.html\n",
      "### http://n.cztv.com/ich/index-2.html\n",
      "### http://n.cztv.com/ich/index-3.html\n",
      "### http://n.cztv.com/ich/index-4.html\n",
      "### http://n.cztv.com/ich/index-5.html\n",
      "### http://n.cztv.com/ich/index-6.html\n",
      "### http://n.cztv.com/ich/index-7.html\n",
      "### http://n.cztv.com/ich/index-8.html\n",
      "### http://n.cztv.com/ich/index-9.html\n",
      "### http://n.cztv.com/ich/index-10.html\n",
      "### http://n.cztv.com/ich/index-11.html\n",
      "### http://n.cztv.com/ich/index-12.html\n",
      "### http://n.cztv.com/ich/index-13.html\n",
      ">>> http://n.cztv.com/news/13815626.html\n",
      ">>> http://n.cztv.com/news/13819509.html\n",
      ">>> http://n.cztv.com/news/13818842.html\n",
      ">>> http://n.cztv.com/news/13818841.html\n",
      ">>> http://n.cztv.com/news/13818840.html\n",
      ">>> http://n.cztv.com/news/13816773.html\n",
      ">>> http://n.cztv.com/news/13816772.html\n",
      ">>> http://n.cztv.com/news/13816725.html\n",
      ">>> http://n.cztv.com/news/13815631.html\n",
      ">>> http://n.cztv.com/news/13815630.html\n",
      ">>> http://n.cztv.com/news/13815629.html\n",
      ">>> http://n.cztv.com/news/13815628.html\n",
      ">>> http://n.cztv.com/news/13815627.html\n",
      ">>> http://n.cztv.com/news/13815625.html\n",
      ">>> http://n.cztv.com/news/13815624.html\n",
      ">>> http://n.cztv.com/news/13815623.html\n",
      ">>> http://n.cztv.com/news/13815600.html\n",
      ">>> http://n.cztv.com/news/13815595.html\n",
      ">>> http://n.cztv.com/news/13815594.html\n",
      ">>> http://n.cztv.com/news/13815593.html\n",
      ">>> http://n.cztv.com/news/13814430.html\n",
      ">>> http://n.cztv.com/news/13814426.html\n",
      ">>> http://n.cztv.com/news/13814400.html\n",
      ">>> http://n.cztv.com/news/13812896.html\n",
      ">>> http://n.cztv.com/news/13812855.html\n",
      ">>> http://n.cztv.com/news/13812684.html\n",
      ">>> http://n.cztv.com/news/13812683.html\n",
      ">>> http://n.cztv.com/news/13812682.html\n",
      ">>> http://n.cztv.com/news/13810699.html\n",
      ">>> http://n.cztv.com/news/13810698.html\n",
      ">>> http://n.cztv.com/news/13806425.html\n",
      ">>> http://n.cztv.com/news/13805489.html\n",
      ">>> http://n.cztv.com/news/13804783.html\n",
      ">>> http://n.cztv.com/news/13804782.html\n",
      ">>> http://n.cztv.com/news/13804497.html\n",
      ">>> http://n.cztv.com/news/13804167.html\n",
      ">>> http://n.cztv.com/news/13804165.html\n",
      ">>> http://n.cztv.com/news/13803486.html\n",
      ">>> http://n.cztv.com/news/13803414.html\n",
      ">>> http://n.cztv.com/news/13803410.html\n",
      ">>> http://n.cztv.com/news/13803408.html\n",
      ">>> http://n.cztv.com/news/13803392.html\n",
      ">>> http://n.cztv.com/news/13802108.html\n",
      ">>> http://n.cztv.com/news/13803052.html\n",
      ">>> http://n.cztv.com/news/13802777.html\n",
      ">>> http://n.cztv.com/news/13802735.html\n",
      ">>> http://n.cztv.com/news/13802118.html\n",
      ">>> http://n.cztv.com/news/13802032.html\n",
      ">>> http://n.cztv.com/news/13801368.html\n",
      ">>> http://n.cztv.com/news/13801367.html\n",
      ">>> http://n.cztv.com/news/13801362.html\n",
      ">>> http://n.cztv.com/news/13801189.html\n",
      ">>> https://ztv.cztv.com/ap/wap/subject/index.shtml?pageId=1005370663\n",
      ">>> http://n.cztv.com/news/13800527.html\n",
      ">>> http://n.cztv.com/news/13800887.html\n",
      ">>> http://n.cztv.com/news/13800874.html\n",
      ">>> http://n.cztv.com/news/13800528.html\n",
      ">>> http://n.cztv.com/news/13785780.html\n",
      ">>> http://n.cztv.com/news/13782778.html\n",
      ">>> http://n.cztv.com/news/13778707.html\n",
      ">>> http://n.cztv.com/news/13778703.html\n",
      ">>> http://n.cztv.com/news/13771292.html\n",
      ">>> http://n.cztv.com/news/13753373.html\n",
      ">>> http://n.cztv.com/news/13747848.html\n",
      ">>> http://n.cztv.com/news/13744328.html\n",
      ">>> http://n.cztv.com/news/13743816.html\n",
      ">>> http://n.cztv.com/news/13732259.html\n",
      ">>> http://m.gityun.cn/h5/gffywt/\n",
      ">>> http://tv.cztv.com/vplay/1201626.html\n"
     ]
    },
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "D:\\python\\Anaconda\\lib\\site-packages\\bs4\\builder\\__init__.py:545: XMLParsedAsHTMLWarning: It looks like you're parsing an XML document using an HTML parser. If this really is an HTML document (maybe it's XHTML?), you can ignore or filter this warning. If it's XML, you should know that using an XML parser will be more reliable. To parse this document as XML, make sure you have the lxml package installed, and pass the keyword argument `features=\"xml\"` into the BeautifulSoup constructor.\n",
      "  warnings.warn(\n"
     ]
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      ">>> http://tv.cztv.com/vplay/1200821.html\n",
      ">>> http://tv.cztv.com/vplay/1199190.html\n",
      ">>> http://tv.cztv.com/vplay/1225332.html\n",
      ">>> http://tv.cztv.com/vplay/1204895.html\n",
      ">>> http://tv.cztv.com/vplay/1190099.html\n",
      ">>> http://tv.cztv.com/vplay/1199772.html\n",
      ">>> http://tv.cztv.com/vplay/1200287.html\n",
      ">>> http://tv.cztv.com/vplay/1206106.html\n",
      ">>> http://tv.cztv.com/vplay/1237938.html\n",
      ">>> http://i.cztv.com/view/13685094.html\n",
      ">>> http://i.cztv.com/view/13706830.html\n",
      ">>> http://i.cztv.com/view/13685436.html\n",
      ">>> http://i.cztv.com/view/13688601.html\n",
      ">>> http://i.cztv.com/view/13688882.html\n",
      ">>> http://i.cztv.com/view/13691731.html\n",
      ">>> http://n.cztv.com/news/13698436.html\n",
      ">>> http://n.cztv.com/news/13700962.html\n",
      ">>> http://m.gityun.cn/h5/gffywt/\n",
      ">>> http://tv.cztv.com/vplay/1243438.html\n",
      ">>> http://tv.cztv.com/vplay/1243433.html\n",
      ">>> http://tv.cztv.com/vplay/1243431.html\n",
      "第 1 篇文章字数： 487\n",
      "资讯丨针尖人生，旗袍制作技艺里的手工温度\n",
      "第 2 篇文章字数： 3907\n",
      " 共创浙江气派的非遗茶生活 ——“中国传统制茶技艺及其相关习俗”入选人类非遗一周年浙江主场活动暨浙江“非遗茶生活” 传统工艺联创大赛成果展在余杭启幕\n",
      "第 3 篇文章字数： 889\n",
      "资讯丨话剧舞台演绎非遗技艺 艺术语言展现传承匠心\n",
      "第 4 篇文章字数： 317\n",
      "资讯丨柯桥非遗亮相国际纺织制造商联合会\n",
      "第 5 篇文章字数： 478\n",
      "资讯丨当影视剧“老戏骨”邂逅平阳木偶戏\n",
      "第 6 篇文章字数： 454\n",
      "浙江省非遗数据体系试点工作培训班在萧山举行\n",
      "第 7 篇文章字数： 751\n",
      "2023年浙江省许林田非遗记录工程导师工作室培训班在龙泉举办\n",
      "第 8 篇文章字数： 1242\n",
      "非遗+地铁，这场快闪真的“泰裤辣”！\n",
      "第 9 篇文章字数： 337\n",
      "资讯丨乐清市非遗馆开展首期越剧公益课\n",
      "第 10 篇文章字数： 447\n",
      "资讯丨新昌调腔新生代折子戏汇报演出圆满成功\n",
      "第 11 篇文章字数： 490\n",
      "资讯丨探寻余杭纸伞，亚残奥委会的外宾们这样说\n",
      "第 12 篇文章字数： 770\n",
      "非遗进校园丨浙江海洋大学迎来首届国风文化节\n",
      "第 13 篇文章字数： 400\n",
      "资讯丨情满慈溪，解锁非遗敬老的多种方式\n",
      "第 14 篇文章字数： 741\n",
      "资讯丨“非遗”绝技进军营 军民共谱“鱼水”情\n",
      "第 15 篇文章字数： 616\n",
      "资讯丨指数激发活力 携手奔赴共富——鹿城区非遗体验基地开展运行活跃指数比拼\n",
      "第 16 篇文章字数： 565\n",
      "资讯丨桐乡市首届重阳民俗活动顺利举办\n",
      "第 17 篇文章字数： 1254\n",
      "资讯丨“喜笑颜开”七十载 一路繁花尽绽放——杭州滑稽艺术剧院举办成立70周年庆典\n",
      "第 18 篇文章字数： 609\n",
      "资讯丨浙里石榴红 共谱民族团结曲\n",
      "第 19 篇文章字数： 508\n",
      "资讯丨乐清非遗GO面商会在乐清市非遗馆召开\n",
      "第 20 篇文章字数： 702\n",
      "资讯丨“白鹿市集”非遗荟萃，共富路上的市井烟火\n",
      "第 21 篇文章字数： 758\n",
      "资讯丨九层重阳糕到底是指哪九层？“塘栖非遗工坊里有老底子的味道！\n",
      "第 22 篇文章字数： 337\n",
      "资讯丨乐清市非遗馆开展首期越剧公益课\n",
      "第 23 篇文章字数： 1171\n",
      "资讯丨东阳竹编九“进”故宫，祖孙三代聚力“传承”\n",
      "第 24 篇文章字数： 364\n",
      "越山向海——浙江省海岛非遗项目在大连华彩绽放\n",
      "第 25 篇文章字数： 400\n",
      "资讯丨《乐清童谣绘本》首发会成功举行\n",
      "第 26 篇文章字数： 881\n",
      "广东省文化和旅游厅一行调研浙江省非物质文化遗产馆\n",
      "第 27 篇文章字数： 521\n",
      "资讯丨方寸天地，以微知著\n",
      "第 28 篇文章字数： 1919\n",
      "资讯丨酿酒+文旅+就业，永嘉县楠江红“永嘉白酒”非遗工坊走出传承新路子\n",
      "第 29 篇文章字数： 792\n",
      "资讯丨临平区2项非遗精彩亮相第五届大运河文化旅游博览会\n",
      "第 30 篇文章字数： 473\n",
      "资讯丨嵊州市探索推进“非遗在社区”工作，推动非遗在城市传播生根\n",
      "第 31 篇文章字数： 1345\n",
      "杭州亚运会｜国际贵宾欣赏浙江非物质文化遗产展示\n",
      "第 32 篇文章字数： 559\n",
      "迎亚运丨万象山海有匠心，象山非遗刮起“亚运风”\n",
      "第 33 篇文章字数： 1045\n",
      "迎亚运丨75岁“打铁”老人，用铁皮铸画敲出“亚运数字火炬手”\n",
      "第 34 篇文章字数： 780\n",
      "约吧·非遗馆丨设计赋能非遗，国内优秀设计师齐聚浙江省非遗馆\n",
      "第 35 篇文章字数： 220\n",
      "浙江省非物质文化遗产馆2023中秋及国庆假期开放公告\n",
      "第 36 篇文章字数： 640\n",
      "迎亚运丨灵心巧手迎亚运，非遗传承人送祝福\n",
      "第 37 篇文章字数： 520\n",
      "资讯丨巧手剪纸 喜迎亚运——非遗剪纸体验课进村镇\n",
      "第 38 篇文章字数： 480\n",
      "资讯丨“喜迎亚运 文化润心”嵊泗海洋剪纸创作实践活动圆满收官\n",
      "第 39 篇文章字数： 434\n",
      "资讯丨海盐县举办非遗传承人和传统工艺专题培训\n",
      "第 40 篇文章字数： 3517\n",
      "资讯丨根植平阳沃土 绽放南孔之花\n",
      "第 41 篇文章字数： 448\n",
      "迎亚运丨藤编《韧之美》，献礼亚运会\n",
      "第 42 篇文章字数： 540\n",
      "迎亚运丨传承非遗 献礼亚运——永嘉木雕传承人创作木雕作品迎亚运\n",
      "第 43 篇文章字数： 1159\n",
      "约吧·非遗馆丨非遗有我，让非遗传承“活”起来\n",
      "第 44 篇文章字数： 921\n",
      "迎亚运丨传承非遗 献礼亚运——桐庐新增两个好去处！\n",
      "第 45 篇文章字数： 478\n",
      "资讯丨温州轨道交通S2线带来非“遗”般的文化之旅\n",
      "第 46 篇文章字数： 1178\n",
      "“意造大观——宋代书法及影响特展” \n",
      "第 47 篇文章字数： 1094\n",
      "资讯丨时隔50年，这首古曲再现！\n",
      "第 48 篇文章字数： 1772\n",
      "颁奖典礼来袭！这些“武林高手”和项目获奖了！\n",
      "第 49 篇文章字数： 2\n",
      "约吧·非遗馆丨本周传统戏剧厅展演预告\n",
      "第 50 篇文章字数： 403\n",
      "浙江省人民政府表扬人类非物质文化遗产申报工作成绩突出集体和个人\n",
      "第 51 篇文章字数： 457\n",
      "迎亚运丨剪出亚运精彩，刻下非遗传承\n",
      "第 52 篇文章字数： 470\n",
      "迎亚运丨嘉善非遗传承人创作特色亚运贝雕邮票\n",
      "第 53 篇文章字数： 6\n",
      "“八八战略”实施20周年特别策划——非遗绽放时代华彩\n",
      "第 54 篇文章字数： 1811\n",
      "非物质文化遗产馆建设工作座谈会在杭州召开\n",
      "第 55 篇文章字数： 517\n",
      "之江文化中心正式启用 王浩出席启用仪式并宣布启用\n",
      "第 56 篇文章字数： 1126\n",
      "2023年“中国传统制茶技艺及其相关习俗”传承人研修班在浙江农林大学开班\n",
      "第 57 篇文章字数： 1092\n",
      "浙江非遗亮相2023“新疆是个好地方”对口援疆19省市非物质文化遗产展\n",
      "第 58 篇文章字数： 1084\n",
      "连接现代生活 绽放时代华彩 第十五届浙江·中国非物质文化遗产博览会在绍兴开幕\n",
      "第 59 篇文章字数： 1169\n",
      "让非遗绽放新活力！“浙”场博览会值得期待\n",
      "第 60 篇文章字数： 2037\n",
      "“可持续发展 非遗同行”——2023“文化和自然遗产日”浙江省主场城市（临海）系列活动启幕\n",
      "第 61 篇文章字数： 707\n",
      "“非遗购物节 浙江消费季”在东阳横店启动\n",
      "第 62 篇文章字数： 1823\n",
      "获奖名单来袭！2023海宁杯浙江非遗年俗短视频大赛结果出炉！\n",
      "第 63 篇文章字数： 1140\n",
      "振兴传统工艺  助力乡村振兴 浙江省开展“非遗助力共同富裕”试点工作\n",
      "第 64 篇文章字数： 46\n",
      "110项！第六批省级非物质文化遗产代表性项目名录公布\n",
      "第 65 篇文章字数： 1801\n",
      "“薪传好时光·浙里幸福年”浙江省2023非遗春晚陪你过大年\n",
      "第 66 篇文章字数： 1899\n",
      "浙里年味丨2023年浙江省“文化进万家——视频直播家乡年”活动正式启动\n",
      "第 67 篇文章字数： 2234\n",
      "浙江美术馆：立足自身特色 提升发展品质\n",
      "第 68 篇文章字数： 6\n",
      "2022年“非遗购物节·浙江消费季”活动火热进行中\n",
      "第 69 篇文章字数： 6\n",
      "《我为家乡非遗好物代言》：十一地市联动代言\n",
      "第 70 篇文章字数： 6\n",
      "《云探店直播》：品味嘉兴月河街美食\n",
      "第 71 篇文章字数： 6\n",
      "《我为家乡非遗好物代言》：青田石雕\n",
      "第 72 篇文章字数： 6\n",
      "《数说非遗》：非遗好物焕发新生\n",
      "第 73 篇文章字数： 6\n",
      "《浙里·非遗传承人》：余杭纸伞的匠心与创新\n",
      "第 74 篇文章字数： 6\n",
      "“非遗薪传”展播：龙凤狮子灯-温州泰顺\n",
      "第 75 篇文章字数： 6\n",
      "《云探店直播》：寻觅杭州湖滨非遗味道\n",
      "第 76 篇文章字数： 6\n",
      "《云探店直播》：探访杭州河坊街非遗“老底子”\n",
      "第 77 篇文章字数： 6\n",
      "宋韵风华展示展演\n",
      "第 78 篇文章字数： 6\n",
      "《数说非遗》：第十四届杭州工艺周\n",
      "第 79 篇文章字数： 2622\n",
      "2022年浙江非遗七大重点活动 精彩浙里看\n",
      "第 80 篇文章字数： 6\n",
      "浙江非遗亮相第七届中国非物质文化遗产博览会\n",
      "第 81 篇文章字数： 1888\n",
      "2022年“非遗购物节·浙江消费季”活动启幕\n",
      "第 82 篇文章字数： 881\n",
      "数百万人打卡“共富指南”非遗数字服务专区\n",
      "第 83 篇文章字数： 1528\n",
      "500余万人次卡浙江非遗“云探店”直播活动\n",
      "第 84 篇文章字数： 2638\n",
      "2022“非遗薪传”系列活动正在火热进行中\n",
      "第 85 篇文章字数： 1710\n",
      "闭幕式来袭！第十四届杭州工艺周精彩回顾\n",
      "第 86 篇文章字数： 1429\n",
      "2022“非遗薪传”获奖名单出炉\n",
      "第 87 篇文章字数： 6\n",
      "共同富裕新力量 共享非遗新生活\n",
      "第 88 篇文章字数： 6\n",
      "“非遗薪传”展播：岭口亭阁花灯 - 磐安县\n",
      "第 89 篇文章字数： 6\n",
      "“非遗薪传”展播：海盐滚灯-海盐县\n",
      "第 90 篇文章字数： 6\n",
      "“非遗薪传”展播：上舍化龙灯-安吉县\n"
     ]
    }
   ],
   "source": [
    "#模块化\n",
    "import re \n",
    "import requests\n",
    "from bs4 import BeautifulSoup\n",
    "from datetime import datetime\n",
    "\n",
    "hd = {'user-agent': 'chrome'}\n",
    "\n",
    "# 获取对应页面下的所有访问网址\n",
    "def get_article_urls(page_url):\n",
    "    r = requests.get(page_url, headers=hd)\n",
    "    soup = BeautifulSoup(r.text)\n",
    "    rtn = []\n",
    "    all_div = soup.find_all('div', class_='txt')\n",
    "    for div in all_div:\n",
    "        rtn.append( div.h3.a['href'])\n",
    "    return rtn\n",
    "\n",
    "#获取一篇新闻的内容，即 body\n",
    "#接收的参数为：：每篇新闻的网址\n",
    "def get_one_article_body(article_url):\n",
    "    r = requests.get(article_url, headers=hd)\n",
    "    r.encoding = 'utf-8'\n",
    "    soup = BeautifulSoup(r.text)\n",
    "    \n",
    "    #获取正文内容\n",
    "    body = soup.find('div', class_='con_show') \n",
    "    if body == None:\n",
    "        body = soup.find('div', class_='detailcontent')\n",
    "        if body == None:\n",
    "            body = '\\n无正文内容'\n",
    "    \n",
    "    if type(body) == str:\n",
    "        return {'body':body}\n",
    "    else:\n",
    "        return {'body':body.get_text()}\n",
    "\n",
    "#在页数的页面：获取对应文章的标题和时间\n",
    "#先获取对应页数的文章网址\n",
    "#再通过访问该网址的相应标签：获取对应文章的标题和时间\n",
    "#再返回标题和时间\n",
    "#接受的参数应该为：新闻的页码网址，对应第几篇文章\n",
    "def get_one_article_Title_Info(page_url,num):\n",
    "    resp = requests.get(page_url,headers=hd)\n",
    "    resp.encoding = 'utf-8'\n",
    "    soup = BeautifulSoup(resp.text)\n",
    "    \n",
    "    divs = soup.find('div', class_='list2').find_all('li')\n",
    "    #获取第num篇文章的标题和时间\n",
    "    title = divs[num-1].h3.a.string#从页面获取到标题\n",
    "    info = divs[num-1].span.string  #从页面获取到时间\n",
    "    #对获取的时间进行处理\n",
    "    time_obj = datetime.strptime(info,\"%Y-%m-%d %H:%M\")\n",
    "    date_part = time_obj.strftime(\"%Y-%m-%d\")\n",
    "    \n",
    "    return {'title':title,\n",
    "            'info':date_part\n",
    "           }\n",
    "\n",
    "#获取对应新闻的标题、时间、正文\n",
    "#调用 get_one_article_Title_Info 函数,得到标题和时间信息\n",
    "#调用 get_one_article_body 函数，得到正文内容\n",
    "#再完成字典的拼接\n",
    "#接收的参数为：第几页的网址，第几篇文章，对应第几篇文章的网址\n",
    "def get_one_article_all(page_url,num,article_url):\n",
    "    information = {}\n",
    "    # 拼接字典\n",
    "    information.update(get_one_article_Title_Info(page_url,num))\n",
    "    information.update(get_one_article_body(article_url))\n",
    "    return information\n",
    "\n",
    "\n",
    "#将读取到的标题、时间、正文写入文本文件\n",
    "def save_one_articles(i,article):\n",
    "    f = open ('txt/'+str(i+1) + '.txt', 'w', encoding = 'utf-8') \n",
    "    f.write(article['title'] + '\\n')\n",
    "    f.write(article['info'] + '\\n')\n",
    "    f.write(article['body'].strip())\n",
    "    f.close()\n",
    "    print('第',i+1,'篇文章字数：',len(article['body']))\n",
    "    print(article['title'])\n",
    "    \n",
    "#保存为文本文件 和.csv文件\n",
    "def save(articles):\n",
    "    ''' 可保存于txt、excel或数据库中 '''\n",
    "    f = open (\"统计.csv\", 'w', encoding = 'utf-8') \n",
    "    f.write('序号,时间,字数,标题\\n')\n",
    "    for i in range (len(articles)) :\n",
    "        line = str(i+1) + ',' #序号\n",
    "        line += articles[i]['info'] + ','  #时间\n",
    "        line += str(len(articles[i]['body'])) + ','  #字数\n",
    "        line += articles[i]['title'] # 标题\n",
    "        f.write(line + '\\n')\n",
    "        save_one_articles(i, articles[i])\n",
    "    f.close()\n",
    "\n",
    "\n",
    "#主函数\n",
    "base = 'http://n.cztv.com/ich/index-'\n",
    "#生成网页对应页数的url\n",
    "page_urls = [base + str(i) + '.html' for i in range(1,14)] #页数有13页\n",
    "\n",
    "#获取所有新闻的url，即应有 12 * 7 + 6= 90 个（第13页只有6个新闻）\n",
    "article_urls = []\n",
    "for page in page_urls:\n",
    "    print('###', page) # 输出访问的页数\n",
    "    tmp = get_article_urls(page)\n",
    "    article_urls.extend( tmp )\n",
    "    \n",
    "articles = []     # 爬取得，所有新闻的title、info、body\n",
    "page_num = 0 # 页数：共 13 页 （0 - 12）\n",
    "news_num = 1 # 篇数：一页 7 篇 ，最后一页 6 篇\n",
    "for url in article_urls:\n",
    "    print('>>>', url)\n",
    "    if news_num >  7: # 篇数达到 7 时（1 - 7）\n",
    "        news_num = 1 #重置，即该页已经访问完毕,将访问位置置为 1\n",
    "        page_num += 1 # 页数+1\n",
    "    if page_num == 12:# 第 13 页时\n",
    "        articles.append( get_one_article_all(page_urls[page_num],news_num,url) )\n",
    "        news_num += 1 # 下一个新闻\n",
    "        continue\n",
    "    articles.append( get_one_article_all(page_urls[page_num],news_num,url) )\n",
    "    news_num += 1 # 下一个新闻\n",
    "\n",
    "#保存新闻\n",
    "save(articles)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "06d7b480",
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3 (ipykernel)",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.9.13"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
